T = int(input())
result = list()


def isSorted(arr):
    for j in range(1, len(arr)):
        if arr[j - 1] > arr[j]:
            return False
    return True


for i in range(T):
    n = int(input())
    arr = input().split()
    for j in range(len(arr)):
        arr[j] = int(arr[j])
    if isSorted(arr):
        result.append("YES")
    else:
        result.append("NO")

for res in result:
    print(res)
